﻿using System.Collections.Generic;
namespace MutsiEngine
{
    class CameraManager
    {
        private int activeCameraIndex;
        private Camera activeCamera;
        SortedList<string, Camera> cameraList;

        #region Properties
        public int ActiveCameraIndex
        {
            get { return activeCameraIndex; }
        }
        public Camera ActiveCamera
        {
            get { return activeCamera; }
        }
        public Camera this[int index]
        {
            get { return cameraList.Values[index]; }
        }
        public Camera this[string id]
        {
            get { return cameraList[id]; }
        }
        public int Count
        {
            get { return cameraList.Count; }
        }
        #endregion

        public CameraManager()
        {
            cameraList = new SortedList<string, Camera>();
            activeCameraIndex = -1;
        }

        public void SetActiveCamera(int cameraIndex)
        {
            activeCameraIndex = cameraIndex;
            activeCamera = cameraList[cameraList.Keys[cameraIndex]];
        }

        public void SetActiveCamera(string id)
        {
            activeCameraIndex = cameraList.IndexOfKey(id);
            activeCamera = cameraList[id];
        }

        public void Clear()
        {
            cameraList.Clear();
            activeCamera = null;
            activeCameraIndex = -1;
        }

        public void Add(string id, Camera camera)
        {
            cameraList.Add(id, camera);
            if (activeCamera == null)
            {
                SetActiveCamera(id);
            }
        }

        public void Remove(string id)
        {
            cameraList.Remove(id);
        }
    }
}
